import * as actionTypes from './constants'

import {
  getTopList,
  getPlayListDetail
} from "@/services/ranking"


const changeTopListsAction = res => ({
  type: actionTypes.CHANGE_TOP_LISTS,
  topLists: res.list,
})

export const changeCurrentIndexAction = index => ({
  type: actionTypes.CHANGE_CURRENT_INDEX,
  currentIndex: index,
})

const changePlayListsAction = res => ({
  type: actionTypes.CHANGE_PLAY_LISTS,
  playLists: res.playlist,
})


export const getTopListsAction = () => {
  return dispatch => {
    getTopList().then(res => {
      dispatch(changeTopListsAction(res));
    })
  }
}

export const getPlayListDetailAction = (id) => {
  return dispatch => {
    getPlayListDetail(id).then(res => {
        dispatch(changePlayListsAction(res));
      })
  }
}